package com.shengsheng.expschedule.service.ucenter.controller.admin;


import com.shengsheng.expschedule.base.result.R;
import com.shengsheng.expschedule.service.ucenter.entity.Vo.RightInfoVo;
import com.shengsheng.expschedule.service.ucenter.service.RightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员权限表 前端控制器
 * </p>
 *
 * @author yuan
 * @since 2021-11-04
 */
@Api(tags = "权限管理")
@RestController
@RequestMapping("/admin/ucenter/right")
@RefreshScope
public class RightController {

    @Autowired
    private RightService rightService;

    @ApiOperation("添加权限")
    @PostMapping("/save")
    public R save(@ApiParam(value = "权限对象",required = true)
                  @RequestBody RightInfoVo rightVo) {
        if (rightService.saveByRightVo(rightVo)) return R.ok().message("添加成功");
        return R.error().message("添加失败");
    }

    @ApiOperation("获取所有权限信息")
    @GetMapping("/getRightsNestedList")
    public R getRightsNestedList() {
        return R.ok()
                .data("NestedList", rightService.getRightsNestedList())
                .message("获取数据成功");
    }

    @ApiOperation("根据权限名查找权限 id")
    @GetMapping("/getRightId/{rightName}")
    public R getRightId(@ApiParam(value = "权限名称",required = true)
                        @PathVariable String rightName) {
        return R.ok()
                .data("rightId", rightService.getRightIdByRightName(rightName))
                .message("获取数据成功");
    }
}

